resource "alicloud_oss_bucket" "main" {
  bucket                    = var.bucket_name
  acl                       = var.acl
  dynamic "website" { //静态页面
    for_each                = var.website
    content {
      error_document        = lookup(website.value, "error_document", null)
      index_document        = website.value.index_document
    }
  } 
  dynamic "logging" { //日志管理
    for_each                = var.logging
    content {
      target_bucket         = logging.value.target_bucket
      target_prefix         = lookup(logging.value, "target_prefix", null)
    }
  }   
  dynamic "referer_config" { //防盗链
    for_each                = var.referer_config
    content {
      allow_empty           = lookup(referer_config.value, "allow_empty", null)
      referers              = referer_config.value.referers
    }
  }
  dynamic "lifecycle_rule" { //生命周期规则
    for_each                = var.lifecycle_rule
    content {
      enabled               = lifecycle_rule.value.enabled
      id                    = lookup(lifecycle_rule.value, "id", null)
      prefix                = lifecycle_rule.value.prefix

      dynamic "expiration" { //过期时间
        for_each            = lookup(lifecycle_rule.value, "expiration", [])
        content {
          date              = lookup(expiration.value, "date", null)
          days              = lookup(expiration.value, "days", null)
        }
      }
    }
  }
  policy                    = var.policy
  storage_class             = var.storage_class
  tags                      = var.tags
}